package com.example.baijiebrower.tools;

import android.content.Context;
import android.content.SharedPreferences;

public class FormData {
    public void saveHeader(Context context , String header){
        SharedPreferences sharedPreferences = context.getSharedPreferences("BAIJIELIUFENG", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        if (!header.isEmpty()){
            editor.putString("header", header);
        }
        editor.apply();
    }
//    public void saveFormData(Context context , String value , String valueKey){
//        SharedPreferences sharedPreferences = context.getSharedPreferences("BaijieERP", context.MODE_PRIVATE);
//        SharedPreferences.Editor editor = sharedPreferences.edit();
//        if (!value.isEmpty()){
//            editor.putString("username", value);
//        }
//        if (!valueKey.isEmpty()){
//            editor.putString("password", valueKey);
//        }
//        editor.apply();
//    }
    public void saveFormData(Context context , String header ,String value , String valueKey){
        SharedPreferences sharedPreferences = context.getSharedPreferences(header, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        if (!value.isEmpty()){
            editor.putString("username", value);
        }
        if (!valueKey.isEmpty()){
            editor.putString("password", valueKey);
        }
        editor.apply();
    }
    public void saveSetHttp(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("BAIJIESETHTTP", Context.MODE_PRIVATE);
        if (sharedPreferences.getBoolean("setHttp", false)){
            return;
        }
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("setHttp", true);
        editor.apply();
    }

    public String getHeader(Context context){
     SharedPreferences sharedPreferences = context.getSharedPreferences("BAIJIELIUFENG", Context.MODE_PRIVATE);
     return sharedPreferences.getString("header", "");
    }

//    public String getValue(Context context){
//        SharedPreferences sharedPreferences = context.getSharedPreferences("BaijieERP", context.MODE_PRIVATE);
//        return sharedPreferences.getString("username", "");
//    }
//
//    public String getValueKey(Context context){
//        return context.getSharedPreferences("BaijieERP", context.MODE_PRIVATE).getString("password", "");
//    }

    public String getHttpValue(Context context , String header){
        SharedPreferences sharedPreferences = context.getSharedPreferences(header, Context.MODE_PRIVATE);
        return sharedPreferences.getString("httpValue", "");
    }

    public void setHttpValue(Context context , String header , String httpValue){
        SharedPreferences sharedPreferences = context.getSharedPreferences(header, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        if (!httpValue.isEmpty()){
            editor.putString("httpValue", httpValue);
        }
        editor.apply();
    }
    public String getValue(Context context , String header){
        SharedPreferences sharedPreferences = context.getSharedPreferences(header, Context.MODE_PRIVATE);
        return sharedPreferences.getString("username", "");
    }

    public String getValueKey(Context context , String header){
        return context.getSharedPreferences(header, Context.MODE_PRIVATE).getString("password", "");
    }

}
